package bird.stack;

import bird.stack.array_stack.ArrayStack;
import bird.stack.linkedlist_stack.LinkedListStack;

/**
 * @author sijunqiang
 * @data 2021/5/24 23:18
 * @description: 比较链表的栈和数组栈的性能
 */
public class CompareLinkedListStackAndArrayStack {

    // 比较 使用不同的队列queue 进行计算qCount个数 的enqueue 和dequeue的耗时。
    public static double testQueue(Stack<Integer> queue, int qCount) {
        double start = System.nanoTime();
        for (int i = 0; i < qCount; i++)
            queue.push(i);
        for (int i = 0; i < qCount; i++)
            queue.pop();
        double end = System.nanoTime();
        double time = (end - start) / 1000000000;
        return time;
    }


    public static void main(String[] args) {
        int qCount = 500000;

        //Test ArrayStack elapsed time
        ArrayStack<Integer> arrayQueue = new ArrayStack<>();
        double time = testQueue(arrayQueue, qCount);
        System.out.println("ArrayQueue: time= " + time + " s");

        //Test LinkedListStack elapsed time
        LinkedListStack<Integer> loopQueue = new LinkedListStack<>();
        double time2 = testQueue(loopQueue, qCount);
        System.out.println("LoopQueue: time= " + time2 + " s");
    }
}
